package impl;
import java.awt.*;
import java.awt.event.*;
import core.*;
import java.util.*;
public class SimplePixelPanel extends PixelPanel implements MouseListener
{
	private static final long serialVersionUID = 1L;
	private int size = 0;
	private Pixel pixel = null;
	private ArrayList<PixelListener> alppl = new ArrayList<PixelListener>();
	public SimplePixelPanel(Pixel pixel)
	{
		size = Parameter.pixelPanelSize;
		this.pixel = pixel;
		setPreferredSize(new Dimension(size,size));
		this.addMouseListener(this);
	}
	@Override
	public void setSize(int i)
	{
		size = i;
		setPreferredSize(new Dimension(size,size));
		repaint();
	}
	@Override
	public Pixel getPixel() 
	{
		return pixel;
	}
	public void setPixel(Pixel pixel) 
	{
		this.pixel = pixel;
		repaint();
	}
	public void paint(Graphics g)
	{
		g.setColor(pixel.getColor());
		g.fillRect(0,0,size,size);
	}
	@Override
	public void addListener(PixelListener ppl) 
	{
		alppl.add(ppl);
	}
	@Override
	public void removeListener(PixelListener ppl) 
	{
		alppl.remove(ppl);		
	}
	public void mouseClicked(MouseEvent arg0) 
	{
		for (int i=0;i<alppl.size();i++)
		{
			PixelListener ppl = alppl.get(i);
			ppl.clicked(pixel);
		}
	}
	public void mouseEntered(MouseEvent arg0) 
	{
	
	}
	public void mouseExited(MouseEvent arg0) 
	{
	
	}
	public void mousePressed(MouseEvent arg0) 
	{
				
	}
	public void mouseReleased(MouseEvent arg0)
	{
				
	}
}
